package com.itheima.mp.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.mp.domain.po.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;


//指定一个实体类, 就是本次要操作的实体类
public interface UserMapper extends BaseMapper<User> {

    // 自定义sql片段                                ew是固定到的写法
    @Update("update user set balance = balance - #{amount} ${ew.customSqlSegment}")
    void updateBalanceByWrapper(@Param("amount") int amount, @Param("ew") LambdaQueryWrapper<User> queryWrapper);

    /**
     * 根据id扣减余额
     *
     * @param id
     * @param amount
     */
    @Update("update user set balance = balance - #{amount} where id = #{id}")
    void deductBalanceById(@Param("amount") int amount, @Param("id") Long id);


}
// 真实开发,中无需这么多无用功,只要是单表操作, 基本都使用mybatis-plus
/*   void saveUser(User user);
    void deleteUser(Long id);
    void updateUser(User user);
    User queryUserById(@Param("id") Long id);
    List<User> queryUserByIds(@Param("ids") List<Long> ids);*/
